package com.wms.wms.service;

import com.wms.wms.entity.User;
import com.wms.wms.mapper.userMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserService {
    @Autowired
    userMapper userMapper;

    /**
     * 用户登录
     * @param adminId 用户名
     * @param password 密码
     * @return UserInfo 用户信息
     */

    public User login(String adminId, String password){
        if (adminId ==null || password == null){
            //TODO异常处理后续完成
            System.out.println("用户名或密码为空！");
        }
        System.out.println("service"+adminId);
        System.out.println(password);
        User user = userMapper.selectByNameAndPwd(adminId,password);
        if (user == null){
            //TODO异常处理后续完成
            System.out.println("用户名或密码错误");
        }
        return user;
    }


    public int edit(User user) {
        if(user.getPassword()==null){
            System.out.println("密码为空！");
        }
        System.out.println("edit"+user.getPassword());
        int i=userMapper.updateByPrimaryKeySelective(user);

        return i;
    }


    public List<User> userList() {
        List<User> list=userMapper.selectAll();

        return list;
    }


    public int deleteUser(String adminId) {
        int x=userMapper.deleteByPrimaryKey(adminId);
        System.out.println("x"+x);
        return x;
    }

    public int editUser(User user) {
        int x=userMapper.updateByPrimaryKey(user);
        return x;
    }

    public User selectUser(String adminId) {
        User user1=userMapper.selectByPrimaryKey(adminId);
        return user1;
    }

    public int insertUser(User user) {
        int x=userMapper.insert(user);
        return x;
    }


}
